home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d945.lha / Reminder / src / src.lha / RemMain.c < prev    next >
C/C++ Source or Header  |  1993-04-19  |  4KB  |  156 lines

  1. /* main() of Reminder */
  2.  
  3. /* $Id: RemMain.c,v 1.8 1993/04/19 11:32:42 Matti_Rintala Exp $ */
  4.  
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <exec/types.h>
  8. #include <dos/dosextens.h>
  9. #include <utility/tagitem.h>
  10. #include <exec/libraries.h>
  11.  
  12. #include <libraries/reqtools.h>
  13.  
  14. #include <intuition/intuition.h>
  15.  
  16. #ifdef __SASC
  17. #include <proto/exec.h>
  18. #include <proto/reqtools.h>
  19. #endif
  20.  
  21. #ifdef _DCC
  22. #include <clib/exec_protos.h>
  23. #include <clib/alib_protos.h>
  24. #include <clib/reqtools_protos.h>
  25. #include <dos/dos.h>
  26. #include <clib/dos_protos.h>
  27. #include <workbench/startup.h>
  28.  
  29. struct Library *CxBase = NULL;    /* DICE does not auto open commodities.library */
  30. struct Library *IconBase = NULL; /* Nor icon.library */
  31. #endif
  32.  
  33. #include "Gadfunc.h"
  34. #include "Globals.h"
  35.  
  36. char *VersionStr = "$VER: Reminder 1.20";
  37.  
  38. struct ReqToolsBase *ReqToolsBase = NULL;
  39.  
  40. /* Variables for setting pr_WindowPtr for ReqTools */
  41. APTR oldwinptr = NULL;
  42. struct Process *myproc;
  43.  
  44.  
  45. static void ClearExit(void);
  46.  
  47. #ifdef _DCC
  48. static struct FileLock *oldlock = NULL;
  49.  
  50. /* DICE uses different entry point for workbench startup */
  51. int wbmain(struct WBStartup *msg) {
  52.  
  53.   /* We have to change to correct directory */
  54.   oldlock = CurrentDir(msg->sm_ArgList[0].wa_Lock);
  55.   return main(0, (char **)msg);    /* Simply call main() */
  56. }
  57. #endif
  58.  
  59. int main(int argc, char **argv) {
  60.  
  61.   UBYTE **ttypes;        /* For argument parsing */
  62.  
  63.   atexit(ClearExit);    /* use ClearExit to release all resources at the end */
  64.  
  65.   /* Open ReqTools */
  66.   if (!(ReqToolsBase =
  67.     (struct ReqToolsBase *)OpenLibrary(REQTOOLSNAME, REQTOOLSVERSION))) {
  68. #ifdef _DCC
  69.     if (argc != 0)        /* DICE doesn't have stdout in Workbench */
  70. #endif
  71.     printf("Needs reqtools.library (version at least %d)!\n", REQTOOLSVERSION);
  72.     exit(-1);
  73.   }
  74.  
  75. #ifdef _DCC
  76.   /* With DICE we have to open commodities.library and icon.library, too */
  77.   if (!(CxBase = OpenLibrary("commodities.library", 0))) {
  78.     if (argc != 0)        /* DICE doesn't have stdout in Workbench */
  79.       printf("Can't open commodities.library!\n");
  80.     exit(-1);
  81.   }
  82.   if (!(IconBase = OpenLibrary("icon.library", 0))) {
  83.     if (argc != 0)        /* DICE doesn't have stdout in Workbench */
  84.       printf("Can't open icon.library!\n");
  85.     exit(-1);
  86.   }
  87. #endif
  88.  
  89.   /* Get the pr_WindowPtr */
  90.   myproc = (struct Process *)FindTask(NULL);
  91.   oldwinptr = myproc->pr_WindowPtr;
  92.  
  93.   /* Set up GadToolsBox screen */
  94.   if (SetupScreen()) {
  95.     rtEZRequestA("Cannot use Workbench screen!", "Quit", NULL, NULL, NULL);
  96.     exit(-1);
  97.   }
  98.  
  99.   /* Open Main-window and set it as this process's window */
  100.   if (OpenMainWindow()) {
  101.     rtEZRequestA("Cannot open a window!", "Quit", NULL, NULL, NULL);
  102.     exit(-1);
  103.   }
  104.   myproc->pr_WindowPtr = MainWnd;
  105.  
  106.   /* Parse command line arguments */
  107.   ttypes = ArgArrayInit(argc, argv);
  108.   /* Try to find database filename */
  109.   filename = ArgString(ttypes, FILETYPE, DEFAULTFILE);
  110.  
  111.   /* Initialize all gadgets */
  112.   InitGadgets();
  113.  
  114.   do {
  115.     WaitPort(MainWnd->UserPort);
  116.   } while (HandleMainIDCMP());
  117.  
  118.   /* Save database and do other exit routines */
  119.   ExitGadgets();
  120.  
  121.   /* Clean up arguments */
  122.   ArgArrayDone();
  123.  
  124.   exit(0);
  125. }
  126.  
  127.  
  128. /* ClearExit closes all resources at exit */
  129. static void ClearExit(void) {
  130.  
  131.   /* Restore windowpointer */
  132.   if (oldwinptr != NULL)
  133.     myproc->pr_WindowPtr = oldwinptr;
  134.  
  135.   /* Close Reqtools */
  136.   if (ReqToolsBase != NULL)
  137.     CloseLibrary((struct Library *)ReqToolsBase);
  138.  
  139. #ifdef _DCC
  140.   /* With DICE we have to close commodities.library and icon.library, too */
  141.   if (CxBase != NULL)
  142.     CloseLibrary(CxBase);
  143.  
  144.   if (IconBase != NULL)
  145.     CloseLibrary(IconBase);
  146.  
  147.   /* Return to correct directory */
  148.   if (oldlock != NULL)
  149.     CurrentDir(oldlock);
  150. #endif
  151.  
  152.   /* Try to close all windows and screens generated by GadToolsBox */
  153.   CloseMainWindow();
  154.   CloseDownScreen();
  155. }
  156.